// @ts-ignore
/* eslint-disable */
import { request } from 'umi';

import {
  AnalysisData,
  CreateTaskReq,
  ImportDataReq,
  TableListItem,
  TaskChartsData,
  TaskListItem,
  TemplateList,
  TestTaskReq,
  TestTaskResp,
} from './data';
import store from 'store';

// 任务列表
export async function getTaskList(
  params: {
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  return request<{
    data: TaskListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/api/task/list', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

// 创建任务
export async function createTask(data: { [key: string]: any }, options?: { [key: string]: any }) {
  return request<CreateTaskReq>('/api/task/create', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

export async function importPolicy(data: { [key: string]: any }, options?: { [key: string]: any }) {
  return request<ImportDataReq>('/api/import-policy', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

// 开始任务
export async function startTask(
  id: number,
  data?: { [key: string]: any },
  options?: { [key: string]: any },
) {
  return request<CreateTaskReq>('/api/task/' + id + '/start', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

// 重启
export async function unpauseTask(
  id: number,
  data?: { [key: string]: any },
  options?: { [key: string]: any },
) {
  return request<CreateTaskReq>('/api/task/' + id + '/unpause', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

// 暂停
export async function pauseTask(
  id: number,
  data?: { [key: string]: any },
  options?: { [key: string]: any },
) {
  return request<CreateTaskReq>('/api/task/' + id + '/pause', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

// 停止
export async function stopTask(
  id: number,
  data?: { [key: string]: any },
  options?: { [key: string]: any },
) {
  return request<CreateTaskReq>('/api/task/' + id + '/stop', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

/** 获取规则列表 GET /api/get_config_list */
export async function getConfigList(
  params: {
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
  corpid?: string,
) {
  return request<{
    data: TableListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/api/get_config_list', {
    method: 'GET',
    params: {
      ...params,
      corpid,
    },
    ...(options || {}),
  });
}

export async function getSmsTemplateList(
  params: {
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  return request<{
    data: TemplateList[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/api/task/sms-template', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

export async function testTask(
  id: number,
  data: { [key: string]: any },
  options?: { [key: string]: any },
) {
  return request<TestTaskResp>(`/api/task/${id}/test`, {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

// 获取某个任务的统计数据
export async function taskChartsData(id: number): Promise<{ data: TaskChartsData }> {
  return request(`/api/task/${id}/charts`, {
    method: 'GET',
  });
}

export async function fakeChartData(id: number): Promise<{ data: AnalysisData }> {
  return request(`/api/t1`, {
    method: 'GET',
  });
}

export async function taskChartsDataDownload(): Promise<{ data: [] }> {
  return request(`/api/task/charts-download`, {
    method: 'GET',
  });
}